﻿using System;
using System.Collections.Generic;
using System.Text;
using Log4Nez.Enumerations;
using System.Reflection;

namespace Log4Nez.Exceptions
{
    [Serializable]
    public class BugException : Exception
    {
        public BugException() { }
        public BugException(string message) : base(message) { }
        public BugException(string message, Exception inner) : base(message, inner) { }

        public BugException(string message, LoggerType loggerType, object logMessage) :
            base(message)
        {
            StringBuilder messageBuilder = new StringBuilder();
            messageBuilder.AppendLine("This could be a bug. Please report this message to us ");
            messageBuilder.AppendLine("===================================================== ");
            messageBuilder.AppendFormat("Exception Message for {0}: {1} \r\n", loggerType.ToString(), message);
            messageBuilder.AppendLine("===================================================== ");
            PropertyInfo[] logProps = logMessage.GetType().GetProperties();
            messageBuilder.AppendFormat("ClassName: {0} \r\n",logMessage.GetType().Name);
            foreach (PropertyInfo prop in logProps)
            {
                messageBuilder.AppendFormat("PropertyName: {0} --> Value: {1} \r\n", prop.Name, prop.GetValue(logMessage, null).ToString());
            }
            messageBuilder.AppendLine("===================================================== ");
            messageBuilder.AppendFormat("Exception Message:\r\n\n {0} \r\n\n, Excpetion StackTrace: \r\n\n {1}", message, this.StackTrace);
            message = messageBuilder.ToString();
        }

        protected BugException(
          System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context)
            : base(info, context) { }
    }
}
